************************************************
***Title: serial_correlation.do
***Creators: Joelle Abramowitz, Shooshan Danagoulian, and Owen Fleming*
***Notes: This file produces a figure depicting the serial correlation in pollen around a high pollen (fourth quartile) day.

*For questions, contact
*Owen Fleming
*hg3490@wayne.edu
************************************************


**********SETUP
use data/for_analysis, clear


**********PRODUCE VISUALIZATION
keep pollen date pollen_quartile_ls county

sort county date

gen fourth_quartile = pollen_quartile_ls==4
gen not_fourth_quartile = fourth_quartile==0

count if fourth_quartile==1
global total = r(N)

sort not_fourth_quartile county date
gen fourth_quartile_number = _n if fourth_quartile==1

forvalues i = 1/$total {
	preserve
	sort not_fourth_quartile county date
	gen days_since_index = date - date[`i']
	keep if county == county[`i']
	keep if inrange(days_since_index,-7,7)
	keep pollen days_since_index pollen_quartile_ls
	tempfile serial`i'
	save `serial`i'', replace
	restore
}

use `serial1', clear
forvalues i = 2/$total {
	append using `serial`i''
}

collapse (mean) pollen, by(days_since_index)

graph bar (asis) pollen, over(days_since_index, gap(0)) bar(1, color(navy) lcolor(white)) ytitle(Average pollen count) b1title("Days relative to 4th Quartile Day") xsize(12) ysize(10)


**********EXPORT
graph export results/serial_correlation.png, replace

